<template>
  <div class="seal-signing-admin">
    <van-nav-bar :border="false" placeholder fixed>
      <template #left>
        <svg-icon name="arrows" @click="topReturnClick" />
      </template>
      <template #title>
        <span class="title-name">印章签名管理</span>
      </template>
    </van-nav-bar>
    <div class="single-seal">
      <div class="title">个人印章</div>
      <van-row>
        <van-col span="12">
          <div class="add-seal" @click="router.push('/painting-signature')">
            <svg-icon name="crucifix" className="seal-icon" />
            <span>手写签名</span>
          </div>
        </van-col>
        <van-col span="12" v-for="item in personalSealList" :key="item">
          <div class="add-seal" @click="settingsDefaulSealClick(item.id, '2')">
            <img :src="item.sealImgData" alt="" />
            <span v-show="item.defaultFlag === 1" class="default">默认</span>
          </div>
        </van-col>
      </van-row>
    </div>
    <div class="single-seal">
      <div class="title">企业印章</div>
      <van-row>
        <van-col span="12" v-for="item in orgSealList" :key="item">
          <div class="add-seal" @click="settingsDefaulSealClick(item.id, '1')">
            <img :src="item.sealImgData" alt="" />
            <span class="seal-name">{{ item.sealName }}</span>
          </div>
        </van-col>
      </van-row>
    </div>
    <div class="end-divider">
      <van-divider
        :style="{ color: '#999', borderColor: '#999', fontSize: '11px' }"
        >没有更多了</van-divider
      >
    </div>
  </div>
  <!-- 底部弹框 -->
  <default-signing-seal
    ref="DefaultSigningSealRef"
    @reload="changeSealSigningList"
  />
</template>

<script lang="ts">
import { defineComponent, ref } from 'vue'
import { useStore } from '@/store'
import { useRouter } from 'vue-router'
import DefaultSigningSeal from './component/default-signing-seal.vue'
import { getSealSignatureList } from '@/api/contract'

export default defineComponent({
  components: { DefaultSigningSeal },
  setup() {
    const router = useRouter()
    const store = useStore()
    // 返回
    const topReturnClick = () => {
      router.push('/personal-center')
    }
    // 获取签名列表
    const personalSealList = ref<any[]>([])
    const orgSealList = ref<any[]>([])
    const changeSealSigningList = async () => {
      const params = {
        idNumber: store.state.login.userInfo.idNumber
      }
      const res = await getSealSignatureList(params)
      if (res.code !== '0') return
      personalSealList.value = []
      orgSealList.value = []
      res.data.records.forEach((item: any) => {
        if (item.sealType === 1) {
          // 公章
          orgSealList.value.push(item)
        } else if (item.sealType === 2) {
          // 个人章
          if (item.defaultFlag === 1) {
            personalSealList.value.unshift(item)
          } else {
            personalSealList.value.push(item)
          }
        }
      })
    }
    changeSealSigningList()
    // 设置签名
    const DefaultSigningSealRef = ref<InstanceType<typeof DefaultSigningSeal>>()
    const settingsDefaulSealClick = (id: string, type: string) => {
      DefaultSigningSealRef.value?.showPopup(id, type)
    }
    return {
      DefaultSigningSealRef,
      personalSealList,
      orgSealList,
      router,
      topReturnClick,
      settingsDefaulSealClick,
      changeSealSigningList
    }
  }
})
</script>

<style scoped lang="less">
.seal-signing-admin {
  height: 100%;
  width: 100%;
  .title-name {
    font-size: 17px;
    color: #101010;
    font-weight: 700;
  }
  .single-seal {
    margin-top: 10px;
    padding: 0 20px 0;
    background-color: #fff;
    .title {
      height: 42px;
      line-height: 42px;
      font-size: 15px;
      color: #101010;
    }
    .van-col:nth-child(even) {
      display: flex;
      flex-direction: column;
      align-items: flex-end;
    }
    .van-col:nth-child(odd) {
      display: flex;
      flex-direction: column;
      align-items: flex-start;
    }
    .add-seal {
      position: relative;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      height: 157px;
      width: 157px;
      margin-bottom: 40px;
      background-color: #f6f6f6;
      border-radius: 5px;
      font-size: 15px;
      color: #999;
      img {
        width: 100%;
      }
      .seal-icon {
        width: 30px;
        height: 30px;
        margin-bottom: 20px;
      }

      .default {
        position: absolute;
        left: 0;
        bottom: -28px;
        display: inline-block;
        height: 18px;
        width: 46px;
        border-radius: 8px;
        border: 1px solid #2489f2;
        text-align: center;
        line-height: 18px;
        font-size: 11px;
        color: #2489f2;
      }
      .seal-name {
        position: absolute;
        left: 0;
        bottom: -28px;
        font-size: 14px;
        color: #101010;
      }
    }
  }
  .end-divider {
    height: 50px;
    padding: 0 90px;
  }
}
</style>
